function loadCommment() {
	$.ajax({
		type: 'get',
		url: 'admin/comments',
		success: function (res) {
			let str = ``
			res.data.forEach(item => {
				let time = item.cdate.substr(0, 10)
				str += `
					<tr>
						<td>${item.id}</td>
						<td>${item.uname}</td>
						<td>${item.content}</td>
						<td>${time}</td>
						<td>
						<button type="button" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn layui-btn-xs delete">删除</button>
						</td>
					</tr>
				`
			})
			$('tbody').html(str)

		}
	})
}
loadCommment()

// 删除评论
$('.layui-table tbody').on('click', '.delete', function (e) {
	let id = $(e.target).data('id')
	layer.confirm('确认要删除吗？', function (index) {
		$.ajax({
			type: 'delete',
			url: 'admin/comments/' + id,
			success: function (res) {
				if (res.status === 0) {
					// 关闭窗口
					layer.close(index)
					// 刷新类别
					loadCommment()
				}
			}
		})
	})
})